<template>
  <div>
    <!-- 大定退款申请车厂审核-->
    <TopFilter :list="topFilterList" :cols="3" @filterChange="changeHandle" @onCollapse="collapseHandle" :labelWidth="110" @resetChange="resetChange"></TopFilter>

    <FilterTables
      ref="table"
      :columns="columns"
      :fetchapi="fetchApi"
      :params="fetchParams"
      :datakey="'records'"
      columnsRef="zjHeadquartersAudit"
      :onRowSelectChange="selectChangeHandle"
      :onColumnsChange="columns => (this.columns = columns)"
    >
      <template slot="controls" >
        <multiuse-button size="small" type="primary" :click="claimExportData">导出</multiuse-button>
      </template>
    </FilterTables>
    <Drawer :visible.sync="isEmit" :title="'车厂大定退款审核'" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <depotModel :rowData="formData" @close="emitcloseHandler" />
    </Drawer>
    <BaseDialog :visible.sync="issearch" :title="'经销商查询'" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <ownerSeacher :type="type" @close="ownercloseHandler" @save="delearSave" selectionType="multiple" />
    </BaseDialog>
    <Drawer :visible.sync="isreject" :title="'车厂大定退款明细'" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <detailModel :rowData="selectedList" @close="rejectclose" />
    </Drawer>
  </div>
</template>
<script>
import { getList ,getClaimListForExport} from '@/api/omSaleP/AutoBigOrderRefundAudit/index.js';
import { dictionary } from '@/utils/dictMixin';
import ownerSeacher from './ownerSeacher';
import detailModel from './detailModel';
import depotModel from './depotModel';
import { exportExcelFile } from '@/utils/index';
import { getAppId } from '@/assets/js/auth'; //获取登录用户
export default {
  name: 'WarehouseMaintenance',
  data() {
    this.BaseTable = null;
    return {
      topFilterList: this.createdFrom(),
      columns: this.createdTable(),
      fetchParams: {
        applyTypeStr: 21581003
      },
       fetchApi: getList,
      formData: {},
      iswarehouse: false,
      isEmit: false,
      issearch: false,
      dealerData: [],
      selectDealerData: [],
      type: 0,
      isOpen: true,
      selectedList: [],
      isreject: false
    };
  },
  mixins: [dictionary],
  components: {
    depotModel,
    ownerSeacher,
    detailModel
  },
  mounted() {
    this.BaseTable = this.$refs.table.$refs.pageTable;
    if (getAppId() == 'beijing') {
      this.isOpen = false;
    }
  },
  created() {},
  methods: {
    createdFrom() {
      return [
        {
          type: 'INPUT',
          label: '客户名称',
          fieldName: 'customerName',
          placeholder: '请输入'
        },
        {
          type: 'INPUT',
          label: '手机号',
          fieldName: 'customerMobile',
          placeholder: '请输入',
        },
        {
          type: 'INPUT',
          label: '大定预订单号',
          fieldName: 'wishApplyNo',
          placeholder: '请输入',
        },
        {
          type: 'SELECT',
          label: '申请状态',
          fieldName: 'applyTypeStr',
          placeholder: '请选择',
          itemList: this.createDictList('2158', [21581001, 21581002, 21581004, 21581007]),
          initialValue: 21581003

        },

        {
          type: 'INPUT',
          label: '申请经销商',
          fieldName: 'dealerName',
          placeholder: '请选择',
          // readonly: true,
          render: (p) => {
            return (
              <div>
                <el-select v-model={this.selectDealerData} disabled={true} multiple collapse-tags placeholder="请选择">
                  {this.dealerData.map((item) => (
                    <el-option key={item.dealerCode} label={item.dealerShortname} value={item.dealerCompanyCode}/>
                  ))}
                </el-select>
                <multiuse-button style="position: absolute;right: 0;height:100%" icon="el-icon-search"
                                 onClick={() => this.issearch = true}/>
              </div>
            );
          },
        },
        {
          type: 'RANGE_DATE',
          label: '申请日期',
          fieldName: 'startDate|endDate',
          placeholder: '请选择',
          dateType: 'exactdaterange',
          initialValue: []
        },
      ];
    },
    createdTable() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          fixed: 'left',
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '操作',
          dataIndex: 'column-action',
          width: 100,
          fixed: 'left',
          render: (props, h) => {
            return (
              <div>
                <multiuse-button size="mini" type="text" disabled={props.row.applyType !== 21581003}
                                 onClick={() => this.editHandle(props.row, 'edit')}>
                  审核
                </multiuse-button>
                <multiuse-button size="mini" type="text" onClick={() => this.detailHandle(props.row, 'show')}>
                  查看
                </multiuse-button>
              </div>
            );
          }
        },
        {
          title: '申请状态',
          dataIndex: 'applyType',
          sorter: true,
          filterItems: this.createDictList('2158'),
          editItems: this.createDictList('2158')
        },
        {
          title: '申请单号',
          dataIndex: 'applyNo',
          sorter: true,
        },
        {
          title: '大定预订单号',
          dataIndex: 'wishApplyNo',
          sorter: true,
        },
        {
          title: '客户名称',
          dataIndex: 'customerName',
          sorter: true,
        },
        {
          title: '手机号',
          dataIndex: 'customerMobile',
          sorter: true,
        },
        {
          title: '大定金额',
          dataIndex: 'largeFixedAmount',
          sorter: true,
        },

        {
          title: '支付时间',
          dataIndex: 'paymentTime',
          sorter: true,
        },
        {
          title: '申请退款时间',
          dataIndex: 'applyRefundTime',
          sorter: true,
        },
        {
          title: '区域审核时间',
          dataIndex: 'areaRauditTime',
          sorter: true,
        },
        {
          title: '车厂审核时间',
          dataIndex: 'factoryRauditTime',
          sorter: true,
        },
        {
          title: '申请经销商',
          dataIndex: 'dealerName',
          sorter: true,
        },
        {
          title: '归属区域',
          dataIndex: 'regional',
          sorter: true,
        },
        {
          title: '申请人',
          dataIndex: 'applyPersonName',
          sorter: true,
        },
        {
          title: '申请理由',
          dataIndex: 'applyReason',
          sorter: true,
        },
        {
          title: '区域审核人',
          dataIndex: 'areaAuditBy',
          sorter: true,
        },
        {
          title: '区域审核意见',
          dataIndex: 'areaAuditOpinion',
          sorter: true,
        },
        {
          title: '车厂审核人',
          dataIndex: 'factoryAuditBy',
          sorter: true,
        },
        {
          title: '车厂审核意见',
          dataIndex: 'factoryAuditOpinion',
          sorter: true,
        },
      ];
    },
    // 车厂审核信息导出
    async claimExportData() {
      await getClaimListForExport(this.fetchParams).then(res => {

        exportExcelFile(res.data, '车厂审核信息导出');
      });
    },
    seacherFun(type) {
      this.type = type;
      this.issearch = true;
    },
    selectChangeHandle(row) {
      if (row.length > 0) {
        let isOpen = true;
        row.map(x => {
          if (x.applyStatus != 60121002) {
            isOpen = false;
          }
        });
        this.isOpen = isOpen ? false : true;
        this.selectedList = row;
      } else {
        this.selectedList = [];
        this.isOpen = true;
        if (getAppId() == 'beijing') {
          this.isOpen = false;
        }
      }
    },
    //搜索获取数据
    changeHandle(params) {
      params.dealerNameStr = this.selectDealerData
      this.fetchParams = Object.assign({}, this.fetchParams, params,{applyTypeStr:!params.applyTypeStr?[21581003, 21581005, 21581006].join(','):params.applyTypeStr});

    },
    collapseHandle() {
      this.$nextTick(() => {
        this.BaseTable.EXECUTE_RESET_HEIGHT();
      });
    },
    delearSave(obj) {
      this.dealerData = obj;
      this.selectDealerData = [];
      obj.forEach(item => {
        this.selectDealerData.push(item.dealerName);
      });
      this.issearch = false;
    },

    ownercloseHandler(val, type) {

      this.issearch = false;
    },
    editHandle(data, type) {
      this.formData = data;
      this.isEmit = true;
    },
    detailHandle(data, type) {
      this.selectedList = data;
      this.isreject = true;
    },
    emitcloseHandler(val) {
      this.isEmit = false;
      this.fetchParams = Object.assign({}, this.fetchParams);

    },
    rejectclose(val) {
      this.isreject = false;
      this.fetchParams = Object.assign({}, this.fetchParams);
    },
    resetChange() {
      this.selectDealerData = []
      this.fetchParams = Object.assign({}, this.fetchParams, {dealerNameStr: this.selectDealerData,applyTypeStr: '21581003'});
    }
  }
};
</script>
